#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
//*
//*Definition for singly - linked list.
//* struct ListNode {
//	*int val;
//	*ListNode* next;
//	*ListNode() : val(0), next(nullptr) {}
//	*ListNode(int x) : val(x), next(nullptr) {}
//	*ListNode(int x, ListNode* next) : val(x), next(next) {}
//	*
//};

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if (head == nullptr)
        {
            return nullptr;
        }
        ListNode* cur = head->next;
        ListNode* first = head;
        while (cur)
        {
            if (cur->val != first->val)
            {
                first->next = cur;
                first = first->next;
            }
            cur = cur->next;
            if (cur == nullptr)
                first->next = nullptr;
        }
        return head;
    }
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
        ListNode* l1 = list1;
        ListNode* l2 = list2;
        ListNode* phead = new ListNode();
        ListNode* head = phead;
        while (l1 && l2)
        {
            if (l1->val <= l2->val)
            {
                head->next = l1;
                l1 = l1->next;
            }
            else {
                head->next = l2;
                l2 = l2->next;
            }
            head = head->next;
        }
        if (l1)
        {
            head->next = l1;
        }
        if (l2)
        {
            head->next = l2;
        }
        return phead->next;
    }
};